package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Studentquestion;
import com.ruoyi.system.service.IStudentquestionService;
import com.ruoyi.common.core.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;

@RestController
@RequestMapping("/system/manageStudent")
public class manageStudent extends BaseController{
    @Autowired
    private IStudentquestionService iStudentquestionService;
    @PreAuthorize("@ss.hasPermi('system:manageStudent:addList')")
    @PostMapping("/addList/{teacherId}")
    public AjaxResult set(@RequestBody List<Studentquestion> studentquestions, @PathVariable Long teacherId)throws TimeoutException{
        String exceptionDate="";

        for (Studentquestion studentquestion:studentquestions){
            if(studentquestion.getTeacherId()==null){
                iStudentquestionService.updateStudentQuestionTeacher(studentquestion.getQuestionId(),teacherId);
                continue;
            }
            if (studentquestion.getTeacherId()!=null){
                exceptionDate+=studentquestion.getQuestion();
                exceptionDate+="    ";
            }
        }
        if (exceptionDate!=""){
            throw new TimeoutException(exceptionDate+"已经被分配");
        }
        return toAjax(1);
    }
}
